﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SES.CMS.BL;
using SES.CMS.DO;

namespace SES.CMS.AdminCP.PageUC
{
    public partial class ucYCKichBan : System.Web.UI.UserControl
    {
        YeuCauKBDO objYC = new YeuCauKBDO();
        KichBanCuoiDO objKB = new KichBanCuoiDO();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["YeuCauKBID"] != null)
            {
                objYC.YeuCauKBID = int.Parse(Request.QueryString["YeuCauKBID"].ToString());
                initForm();
            }
        }

        private void initForm()
        {
            objYC = new YeuCauKBBL().Select(objYC);
            objKB = new KichBanCuoiBL().SelectByYC(objYC.YeuCauKBID);

            chkChapNhan.Checked = objYC.ChapNhan;
            txtUserName.Text = objYC.TenDangNhap;
            txtMatKhau.Text = objYC.MatKhai;


            lblTenChuRe.Text = objYC.TenChuRe;
            lblTenCoDau.Text = objYC.TenCoDau;
            lblNhaChuRe.Text = objYC.DiaChiNhaTrai;
            lblNhaCoDau.Text = objYC.DiaChiNhaGai;
            lblHDamNgo.Text = objYC.GioDamNgo + "H" + objYC.PhutDamNgo + "p";
            lblNgayDamNgo.Text = objYC.NgayDamNgo;
            lblNgayAnHoi.Text = objYC.NgayAnHoi;
            lblGioDenNG.Text = objYC.GioAnHoi + "H" + objYC.PhutAnHoi + "p";
            lblGioDenNGTH.Text = objYC.GioTiecCuoi + "H" + objYC.PhutTiecCuoi + "p";
            lblNgayThanhHon.Text = objYC.NgayTiecCuoi;
            lblNTKhoiHanh.Text = objKB.GioNTKhoiHanhAH;
            lblNTKhoiHanhTH.Text = objKB.GioNTKhoiHanhTH;
            lblDichVuAH.Text = objKB.DVLeAnHoi;
            lblDichVuNC.Text = objKB.DVLeCuoi;

            txt1.Text = objKB.TGLeDamNgo;
            txt2.Text = objKB.TGLeAnHoi;
            txt3.Text = objKB.AHLoTrinhNTNG;
            txt4.Text = objKB.AHLoTrinhNGNT;
            txt5.Text = objKB.TGTrapNamCoMatNT;
            txt6.Text = objKB.TGTrapNamCoMatNT;
            txt6.Text = objKB.TGTrapNuCoMatNG;
            txt7.Text = objKB.TGLeCuoi;
            txt8.Text = objKB.XeGanHoa;
            txt9.Text = objKB.XeCoMatNT;
            txt10.Text = objKB.LCLoTrinhNTNG;
            txt11.Text = objKB.LCLoTrinhNGNT;
            txt12.Text = objKB.LCLoTrinhNGRaDT;
            tt4.Text = objKB.QTChupAnhTrapAH;
            tt5.Text = objKB.QTKhoiHanhNhatraiAH;
            tt6.Text = objKB.QTDenNhaGaiNgoiAH;
            tt23.Text = objKB.QTTrapNamMangLeLQVeAH;
            tt24.Text = objKB.QTLayLeXinDauCuaHangLC;
            txt25.Text = objKB.QTDoanXinDenNTLC;
            txt26.Text = objKB.QT2NguoiVaoNG;
            txt27.Text = objKB.QTNGDonNT;
            txt28.Text = objKB.QTNTOnDinhCho;
            txt35.Text = objKB.QTNGDiCungNT;
            txt31.Text = objKB.QTNTXinPhepHoa;
            txt36.Text = objKB.QT2HoOnDinh;
            txt42.Text = objKB.QT2NhaRaDiemTiec;
            txt43.Text = objKB.CDCRDenTruocDon;
            txt44.Text = objKB.BoMeDonKhach;
            txt46.Text = objKB.BoMeCamOn;
            

        }

        protected void btnCapNhat2_Click(object sender, EventArgs e)
        {
            initKBYC();

        }

        private void initKBYC()
        {
            objYC.ChapNhan = chkChapNhan.Checked;
            objYC.TenDangNhap = txtUserName.Text;
            objYC.MatKhai = txtMatKhau.Text;
            new YeuCauKBBL().Update(objYC);

            objKB.TGLeDamNgo = txt1.Text;
            objKB.TGLeAnHoi = txt2.Text;
            objKB.AHLoTrinhNTNG = txt3.Text;
            objKB.AHLoTrinhNGNT = txt4.Text;
            objKB.TGTrapNamCoMatNT = txt5.Text;
            objKB.TGTrapNamCoMatNT = txt6.Text;
            objKB.TGTrapNuCoMatNG = txt6.Text;
            objKB.TGLeCuoi = txt7.Text;
            objKB.XeGanHoa = txt8.Text;
            objKB.XeCoMatNT = txt9.Text;
            objKB.LCLoTrinhNTNG = txt10.Text;
            objKB.LCLoTrinhNGNT = txt11.Text;
            objKB.LCLoTrinhNGRaDT = txt12.Text;
            objKB.QTChupAnhTrapAH = tt4.Text;
            objKB.QTKhoiHanhNhatraiAH = tt5.Text;
            objKB.QTDenNhaGaiNgoiAH = tt6.Text;
            objKB.QTTrapNamMangLeLQVeAH = tt23.Text;
            objKB.QTLayLeXinDauCuaHangLC = tt24.Text;
            objKB.QTDoanXinDenNTLC = txt25.Text;
            objKB.QT2NguoiVaoNG = txt26.Text;
            objKB.QTNGDonNT = txt27.Text;
            objKB.QTNTOnDinhCho = txt28.Text;
            objKB.QTNGDiCungNT = txt35.Text;
            objKB.QTNTXinPhepHoa = txt31.Text;
            objKB.QT2HoOnDinh = txt36.Text;
            objKB.QT2NhaRaDiemTiec = txt42.Text;
            objKB.CDCRDenTruocDon = txt43.Text;
            objKB.BoMeDonKhach = txt44.Text;
            objKB.BoMeCamOn = txt46.Text;
            objKB.GioNTKhoiHanhAH = lblNTKhoiHanh.Text;
            objKB.GioNTKhoiHanhTH = lblNTKhoiHanhTH.Text;
            new KichBanCuoiBL().Update(objKB);
        }

        protected void btnCapNhat_Click(object sender, EventArgs e)
        {
            initKBYC();
        }
    }
}